var options = {
	title: {
        text: '运输类型箱量统计'
    },
    tooltip : {
        trigger: 'axis',
        axisPointer : {            // 坐标轴指示器，坐标轴触发有效
            type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
        }
    },
    legend: {
        data:['铁水','水铁']
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    xAxis: {
        data: []
    },
    yAxis: {
    },
    series: 
	[ {
		name : '铁水',
		type : 'bar',
		data : []
	},{
		name : '水铁',
		type : 'bar',
		data : []
	}]
 };


var xlChart = echarts.init(document.getElementById('xldiv'));
xlChart.setOption(options);
load("/front/Statistics/xlStatistics.action?tjflag=2", xlChart);

/***加载数据***/
function load(url, myChart){
    $.get(mainDomain + url).done(function (data) {
        var tsxlxx = [],stxlxx = [];
        
        $.each(data.categories, function(n, item){
        	tsxlxx.push(0);
        	stxlxx.push(0);
        })
        
        var replaceindex;
        $.each(data.list, function(i, entry){
            if("A" == entry.type){
            	replaceindex = $.inArray(entry.df,data.categories);
            	if(replaceindex!=-1){
            		tsxlxx.splice(replaceindex,1,entry.count);
            	}
                return;
            }else if("B" == entry.type){
            	replaceindex = $.inArray(entry.df,data.categories);
            	if(replaceindex!=-1){
            		stxlxx.splice(replaceindex,1,entry.count);
            	}
                return;
            }
        });
        
        // 填入数据
        myChart.setOption({
            xAxis: {
                data: data.categories
            },
            yAxis : 
            	[ {
				name : '箱量'
			}],
            series: 
            	[ {
				name : '铁水',
				type : 'bar',
				barWidth: '30%',
				data : tsxlxx
			},{
				name : '水铁',
				type : 'bar',
				barWidth: '30%',
				data : stxlxx
			} ]
        });
    });
}